@extends('layout.master')

@section('title','回复帖子')

@section('css')
    @parent
    <link href="{{ asset('plugins/bower_components/summernote/dist/summernote.css') }}" rel="stylesheet"/>
    <!-- animation CSS -->
    <link href="{{ asset('css/animate.css') }}" rel="stylesheet">
    <link href="{{ asset('plugins/bower_components/icheck/skins/all.css') }}" rel="stylesheet">
    <link href="{{ asset('plugins/bower_components/bootstrap-switch/bootstrap-switch.min.css') }}" rel="stylesheet">
@endsection
@section('main')

    @if (session('message'))
        <div>
            <input type="hidden" id="hidden" name="hidden" value="hidden">
            <input type="hidden" id="message" name="message" value="{{ session('message') }}">
            <input type="hidden" id="status" name="status" value="{{ session('status') }}">
        </div>
    @endif

    <div class="row">

        <div class="col-lg-12 col-md-12">
            <div class="white-box">
                <div class="row">
                    <div class="col-md-12 col-sm-8">
                        <div class="row">
                            <div class="col-md-2 col-sm-4">
                                <div class="row">
                                    <div class="col-md-12 col-sm-12">
                                        <img src="{{ $tiezi['c_avatar'] }}" width="80%"/>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-12 col-sm-12">
                                        {{ $tiezi['name'] }}
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-12 col-sm-12">
                                        {{ $tiezi['pub_time'] }}
                                    </div>
                                </div>

                            </div>
                            <div class="col-md-10 col-sm-4">
                                <div class="row">
                                    <div class="col-md-12 col-sm-12">
                                        {{ $tiezi['keshi'] . '--' . $tiezi['huati'] . '--' . $tiezi['title'] }}

                                        @if($tiezi['is_hot'] === \App\Postings::HOT_YES)
                                            <button class='btn btn-info' onclick=qxjj({{ $tiezi['archive_id'] }})>取消加精
                                            </button>
                                        @else
                                            <button class='btn btn-success' onclick=jj({{ $tiezi['archive_id'] }})>加精
                                            </button>
                                        @endif
                                    </div>
                                </div>
                                <p style="font-size: large">{{ $tiezi['content'] }}</p>
                            </div>
                        </div>
                        <div class="row">
                            @if(isset($tiezi['video']))
                                <div align="center" class="col-md-12 col-sm-12">
                                    <video controls>
                                        <source src="{{ $tiezi['video'] }}" type="video/mp4">
                                        <source src="{{ $tiezi['video'] }}" type="video/ogg">
                                        <source src="{{ $tiezi['video'] }}" type="video/webm">
                                        <object data="{{ $tiezi['video'] }}">
                                            <embed src="{{ $tiezi['video'] }}">
                                        </object>
                                    </video>
                                </div>
                            @elseif(isset($tiezi['pic']))
                                @foreach($tiezi['pic'] as $value)
                                    <div class="col-md-4 col-sm-6" align="center">
                                        <img src="{{ $value['path'] }}" style="width:80%;"/>
                                        <div class="row">
                                            <hr width="100%"/>
                                        </div>
                                    </div>
                                @endforeach
                            @endif
                        </div>
                    </div>
                </div>


                @if($tiezi['ping_num'] !== 0)
                    <div class="row">
                        @foreach($huifu as $value)
                            <div class="col-lg-12 col-md-12">
                                <div class="white-box">
                                    <div class="row">
                                        <div class="col-md-6 col-sm-6">
                                            <div class="row">
                                                <div class="col-md-3 col-sm-3">
                                                    <div class="row">
                                                        <div class="col-md-12 col-sm-12">
                                                            <img src="{{ $value['c_avatar'] }}" width="80%"/>
                                                        </div>
                                                    </div>
                                                    <div class="row">
                                                        <div class="col-md-12 col-sm-12">
                                                            {{ $value['name'] }}
                                                        </div>
                                                    </div>
                                                    <div class="row">
                                                        <div class="col-md-12 col-sm-12">
                                                            {{ $value['create_time'] }}
                                                        </div>
                                                    </div>

                                                </div>
                                                <div class="col-md-9 col-sm-9">
                                                    <p style="font-size: large">{{ $value['content'] }}</p>
                                                </div>
                                            </div>
                                            <div class="row">
                                                <div class="col-md-6 col-sm-6">
                                                    <a style="color: #8b131b"
                                                       href="###" onclick=replys({{ $value['id'] }})>回复</a>
                                                </div>
                                                <div class="col-md-6 col-sm-6">
                                                    <a style="color: #8b131b"
                                                       href="###" onclick=dels({{ $value['id'] }})>删除</a>
                                                </div>
                                            </div>
                                            <div class="row" id="reply-{{ $value['id'] }}" style="display:none;">
                                                <textarea style="width: 80%" type="text"
                                                          id="replys-{{ $value['id'] }}"></textarea>
                                                <input type="text" name="view_time" id="view-time-{{ $value['id'] }}"
                                                       placeholder="显示时间:2019-01-15 12:12:12 不填为即时"
                                                       class="form-control form-control-line">
                                                <button class="fcbtn btn btn-success btn-outline btn-1e waves-effect"
                                                        style="width: 20%"
                                                        onclick=rereplys({{ $value['id'] }})>回复
                                                </button>
                                            </div>
                                        </div>
                                        @if($value['replys'])
                                            <div class="col-md-6 col-sm-6" style="font-size: small">
                                                @foreach($value['replys'] as $reply)
                                                    <div class="row">
                                                        <div class="col-md-12 col-sm-12">
                                                            <div class="row">
                                                                <p>
                                                                    <f style="color: #0c91e5">{{ $reply->user_name }} </f>
                                                                    @if($reply->reuser_id)
                                                                        &nbsp;&nbsp;回复：&nbsp;
                                                                        <f style="color: #0c91e5">{{ $reply->reuser_name }}</f>
                                                                    @endif
                                                                </p>
                                                                <p>&nbsp;&nbsp;&nbsp;{{ $reply->content }}</p>
                                                                <p>
                                                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ $reply->create_time }}</p>
                                                                <a id="a-{{ $reply->id }}" style="color: #8b131b"
                                                                   href="###"
                                                                   onclick=reply({{ $reply->id }})>&nbsp;&nbsp;&nbsp;回复</a>
                                                                <a id="b-{{ $reply->id }}" style="color: #8b131b"
                                                                   href="###"
                                                                   onclick=del({{ $reply->id }})>&nbsp;&nbsp;&nbsp;删除</a>
                                                            </div>
                                                            <div class="row" style="display:none;"
                                                                 id="div-{{ $reply->id }}">
                                                                <textarea id="input-{{ $reply->id }}" style="width: 80%"
                                                                          type="text"></textarea>
                                                                <input type="text" name="view_time"
                                                                       id="re-view-time-{{ $reply->id }}"
                                                                       placeholder="显示时间:2019-01-15 12:12:12 不填为即时"
                                                                       class="form-control form-control-line">
                                                                <button class="fcbtn btn btn-success btn-outline btn-1e waves-effect"
                                                                        style="width: 20%"
                                                                        onclick=rereply({{ $reply->id }})>回复
                                                                </button>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <hr/>

                                                @endforeach
                                            </div>
                                        @endif
                                    </div>
                                </div>
                            </div>
                        @endforeach


                        @if($pages > 1)
                            <ul class="pagination">
                                <li><a href="#"><i class="fa fa-angle-left"></i></a></li>
                                @for($i = 1;$i <= $pages;$i++)
                                    <li>
                                        <a href="/postings/detail/{{ $tiezi['archive_id'] }}/{{ $i }}">{{ $i }}</a>
                                    </li>
                                @endfor
                                <li><a href="#"><i class="fa fa-angle-right"></i></a></li>
                            </ul>
                        @endif
                    </div>
                @endif

                <form class="form-horizontal form-material" id="posting" method="post" action="/postings/posting"
                      enctype="multipart/form-data">
                    <input type="hidden" value="{{ $tiezi['archive_id'] }}" id="archive-id" name="archive_id"/>
                    <div class="row">
                        <div class="col-md-12 col-sm-12">
                            <div id="push-booter">
                                <div class="row">
                                    <div class="col-sm-12">
                                        <textarea style="height: 150px; width: 100%;overflow:auto;" name="contents"
                                                  id="contents"></textarea>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <input type="text" name="view_time"
                               id="view-time"
                               placeholder="显示时间:2019-01-15 12:12:12 不填为即时"
                               class="form-control form-control-line">
                    </div>
                    <div class="form-group">
                        <div class="row">
                            <div class="col-md-2 col-sm-2">
                                <button class="fcbtn btn btn-success btn-outline btn-1e waves-effect" id="reposting">回复帖子
                                </button>
                            </div>
                            {!! csrf_field() !!}
                            <label class="control-label">选择用户</label>
                            <div class="example">
                                <select style="height: 38px" name="user_id" id="user-id">
                                    @foreach(App\User::PostingsUsers() as $value)
                                        <option value="{{ $value->c_id }}">{{ $value->name }}</option>
                                    @endforeach
                                </select>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
@endsection
@section('js')
    @parent
    <!-- icheck -->
    <script src="{{ asset('plugins/bower_components/icheck/icheck.min.js') }}"></script>
    <script src="{{ asset('plugins/bower_components/icheck/icheck.init.js') }}"></script>
    <script src="{{ asset('js/jasny-bootstrap.js') }}"></script>
    <!-- jQuery file upload -->
    <script src="{{ asset('plugins/bower_components/dropify/dist/js/dropify.min.js') }}"></script>
    <script src="{{ asset('plugins/bower_components/summernote/dist/summernote.min.js') }}"></script>
    <script>
        $(document).ready(function () {
            // Basic
            $('.dropify').dropify();
        });
    </script>
    <script src="{{ asset('plugins/bower_components/bootstrap-select/bootstrap-select.min.js') }}"
            type="text/javascript"></script>
    <!-- bt-switch -->
    <script src="{{ asset('plugins/bower_components/bootstrap-switch/bootstrap-switch.min.js') }}"></script>
    <script type="text/javascript">

        jQuery(document).ready(function () {

            $('.summernote').summernote({
                height: 350, // set editor height
                minHeight: null, // set minimum height of editor
                maxHeight: null, // set maximum height of editor
                focus: false, // set focus to editable area after initializing summernote$('.summernote').summernote({
                toolbar: [
                    // [groupName, [list of button]]
                    ['style', ['bold', 'italic', 'underline', 'clear']],
                    ['fontsize', ['fontsize']],
                    ['fontname', ['fontname']],
                    ['color', ['color']],
                    ['para', ['ul', 'ol', 'paragraph']],
                    ['height', ['height']],
                    ['insert', ['link', 'picture', 'video']],
                    ['view', ['fullscreen', 'codeview', 'help']]
                ],
                lang: 'zh-CN',
                // placeholder: '内容',
                dialogsFade: true,
            });

            $('.inline-editor').summernote({
                airMode: true
            });

        });

        $(".bt-switch input[type='checkbox'], .bt-switch input[type='radio']").bootstrapSwitch();
        var radioswitch = function () {
            var bt = function () {
                $(".radio-switch").on("switch-change", function () {
                    $(".radio-switch").bootstrapSwitch("toggleRadioState")
                }),
                    $(".radio-switch").on("switch-change", function () {
                        $(".radio-switch").bootstrapSwitch("toggleRadioStateAllowUncheck")
                    }),
                    $(".radio-switch").on("switch-change", function () {
                        $(".radio-switch").bootstrapSwitch("toggleRadioStateAllowUncheck", !1)
                    })
            };
            return {
                init: function () {
                    bt()
                }
            }
        }();
        $(document).ready(function () {
            radioswitch.init()
        });


        $(document).ready(function () {
            var hidden = $('#hidden').val();
            if (hidden === 'hidden') {
                if ($('#status').val() == 1) {
                    toastsuccess($('#message').val());
                } else {
                    toasterror($('#message').val());
                }
            }
        });

        function reply(sid) {
            $("#div-" + sid).show();
        }


        //回复楼层的回复
        function rereply(sid) {
            var contents = $("#input-" + sid).val();
            var view_time = $("#re-view-time-" + sid).val();
            var user_id = $("#user-id").val();
            swal({
                    title: "",
                    text: "确定回复么？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/posting/rereply',
                        type: 'POST',
                        data: {reply_id: sid, user_id: user_id, contents: contents, view_time: view_time},
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            }
                        }
                    })
                }
            );
        }


        //回复楼层
        function replys(sid) {
            $("#reply-" + sid).show();
        }

        function rereplys(sid) {
            var contents = $("#replys-" + sid).val();
            var view_time = $("#view-time-" + sid).val();
            var user_id = $("#user-id").val();
            swal({
                    title: "",
                    text: "确定回复么？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/posting/rereplys',
                        type: 'POST',
                        data: {actchive_id: sid, user_id: user_id, contents: contents, view_time: view_time},
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            }
                        }
                    })
                }
            );
        }

        $("#reposting").click(function (e) {
            e.preventDefault();
            var archive_id = $("#archive-id").val();
            var contents = $("#contents").val();
            var view_time = $("#view-time").val();
            var user_id = $("#user-id").val();
            swal({
                    title: "",
                    text: "确定回复么？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/postings/posting',
                        type: 'POST',
                        data: {
                            user_id: user_id,
                            contents: contents,
                            view_time: view_time,
                            archive_id: archive_id
                        },
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            }
                        }
                    })
                }
            );
        });

        //删除楼层
        function dels(sid) {
            swal({
                    title: "",
                    text: "确定回复么？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/posting/rereplys/dels/' + sid,
                        type: 'POST',
                        data: {id: sid},
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            }
                        }
                    })
                }
            );
        }


        //删除楼层回复
        function del(sid) {
            swal({
                    title: "",
                    text: "确定回复么？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/posting/rereply/del/' + sid,
                        type: 'POST',
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            }
                        }
                    })
                }
            );
        }

        function jj(sid) {
            swal({
                    title: "",
                    text: "确定加精吗？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/posting/jj/' + sid,
                        type: 'POST',
                        error: function (e) {
                            if (e.readyState === 4 && e.status === 422) {
                                for (var i in e.responseJSON) {
                                    if (e.responseJSON[i] !== 'The given data was invalid.') {
                                        err = e.responseJSON[i];
                                        for (var j in err) {
                                            toasterror(err[j][0]);
                                        }
                                    }
                                }
                            }
                        },
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            }
                        }
                    })
                }
            );
        }


        function qxjj(sid) {
            swal({
                    title: "",
                    text: "确定取消加精吗？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/posting/qjj/' + sid,
                        type: 'POST',
                        error: function (e) {
                            if (e.readyState === 4 && e.status === 422) {
                                for (var i in e.responseJSON) {
                                    if (e.responseJSON[i] !== 'The given data was invalid.') {
                                        err = e.responseJSON[i];
                                        for (var j in err) {
                                            toasterror(err[j][0]);
                                        }
                                    }
                                }
                            }
                        },
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            }
                        }
                    })
                }
            );
        }

    </script>
@endsection